<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：选择当天未工作人员-->
<div th:fragment="appointimemainUser" class="modal inmodal fade" id="appointimemainUser_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">选择工作人员</h4>
                <small class="font-bold"></small>
            </div>
            <div class="modal-body">
                <table id="appointimemainUser_table" class="table table-striped"></table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="appointimemainUserObj.submitHandler()">
                    保存
                </button>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            appointimemainUserObj.myTable = $('#appointimemainUser_table').bootstrapTable({
                clickToSelect: true,
                method: 'post',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    checkbox: true,
                    width: 50,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '工作人员',
                    field: 'name'
                }, {
                    title: '工作时间间隔（分钟）',
                    field: 'interval'
                }, {
                    title: '自动生成工作时间',
                    field: 'isAuto',
                    formatter: function (value, row, index) {
                        return value ? "是" : "否";
                    }
                }],
                responseHandler: function (res) {
                    return res.list;
                }
            });
        })
        var appointimemainUserObj = new Object({
            appoinDate: undefined,
            myTable: undefined,
            init: function (appoinDate) {
                appointimemainUserObj.appoinDate = appoinDate;
                appointimemainUserObj.myTable.bootstrapTable('refresh', {
                    url: '/appoin/appointimemain/noWorkUserList',
                    query: {
                        appoinDate: appoinDate
                    }
                });
                $('#appointimemainUser_Modal').modal('show')
            },
            submitHandler: function () {
                let selectUsers = appointimemainUserObj.myTable.bootstrapTable('getSelections');
                if (selectUsers.length == 0) {
                    $.mySwalWarn("请选择工作人员");
                    return;
                }
                let userCodes = selectUsers.map(o => {
                    return o.userCode;
                });
                $.mySwalConfirm('将为选中的工作人员添加工作时间，确认吗？', function () {
                    $.myPost({
                        url: `/appoin/appointimemain/saveWorkUser`,
                        dataType: 'json',
                        data: {
                            userCodes: userCodes,
                            appoinDate: appointimemainUserObj.appoinDate
                        },
                        success: function (data) {
                            if (data && data.code === 0) {
                                toastr.success(data.msg, '操作提示')
                                appointimemainListObj.updateCalendarEvent();
                                appointimemainListObj.refreshList();
                                $('#appointimemainUser_Modal').modal('hide')
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                });
            }
        })
    </script>
</div>
</body>
</html>